<?php
namespace Clover\Controller;

use Think\Controller;

class PromotionController extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        session('menu', "promotion");
    }


    public function index()
    {
        check_privilege();
        $login_status = D("Admin")->get_login_status();
        if (empty($login_status)) {
            $this->redirect('/Clover/login');
        }
        session('menu_sub', "promotion_list");
        $start_time = (I("get.start_time", ""));
        $end_time = (I("get.end_time", ""));

        $_end_time = !empty($end_time) ? strtotime($end_time) + 3600 * 24 : "";
        $_start_time = !empty($start_time) ? strtotime($start_time) : "";
        $data = array(
            "start_time" => $_start_time,
            "end_time" => $_end_time
        );
        $promotion_list = D("Promotion")->get_promotion_list($data);
        $data = array(
            "promotion_list" => $promotion_list,
            "start_time" => $start_time,
            "end_time" => $end_time
        );
        $this->assign($data);
        $this->display("promotion_list");
    }

    public function chart()
    {
        check_privilege();
        $login_status = D("Admin")->get_login_status();
        if (empty($login_status)) {
            $this->redirect('/Clover/login');
        }
        session('menu_sub', "promotion_chart");
        //时间生成代码
        /* $promotion_list = D('Promotion')->table('dsk_promotion')->select();
         foreach ($promotion_list as $key => $value) {
          $fulltime =  strtotime($value['dt']);
           $data = array("fulltime"=>$fulltime);
           M('Promotion')->where("id=".$value['id'])->save($data);
         }*/
        $start_time = (I("get.start_time", ""));
        $end_time = (I("get.end_time", ""));


        $_end_time = !empty($end_time) ? strtotime($end_time) + 3600 * 24 : "";
        $_start_time = !empty($start_time) ? strtotime($start_time) : "";
        $data = array(
            "start_time" => $_start_time,
            "end_time" => $_end_time
        );
        $dubooker = D("promotion")->get_pnum_by_dsknum("dubooker", $data);
        $dsk002 = D("promotion")->get_pnum_by_dsknum("dsk002", $data);
        $dsk004 = D("promotion")->get_pnum_by_dsknum("dsk004", $data);
        $dsk005 = D("promotion")->get_pnum_by_dsknum("dsk005", $data);
        $dsk006 = D("promotion")->get_pnum_by_dsknum("dsk006", $data);
        $dsk008 = D("promotion")->get_pnum_by_dsknum("dsk008", $data);
        $dsk009 = D("promotion")->get_pnum_by_dsknum("dsk009", $data);
        $dsk010 = D("promotion")->get_pnum_by_dsknum("dsk010", $data);
        $dsk011 = D("promotion")->get_pnum_by_dsknum("dsk011", $data);
        $dsk012 = D("promotion")->get_pnum_by_dsknum("dsk012", $data);
        $dsk013 = D("promotion")->get_pnum_by_dsknum("dsk013", $data);
        $dsk014 = D("promotion")->get_pnum_by_dsknum("dsk014", $data);
        $dsk018 = D("promotion")->get_pnum_by_dsknum("dsk018", $data);
        $dsk019 = D("promotion")->get_pnum_by_dsknum("dsk019", $data);
        $pnum = array(
            "dubooker" => $dubooker,
            "dsk002" => $dsk002,
            "dsk004" => $dsk004,
            "dsk005" => $dsk005,
            "dsk006" => $dsk006,
            "dsk008" => $dsk008,
            "dsk009" => $dsk009,
            "dsk010" => $dsk010,
            "dsk011" => $dsk011,
            "dsk012" => $dsk012,
            "dsk013" => $dsk013,
            "dsk014" => $dsk014,
            "dsk018" => $dsk018,
            "dsk019" => $dsk019,
        );
        $data = array(
            "pnum" => $pnum,
            "start_time" => $start_time,
            "end_time" => $end_time
        );
        $this->assign($data);
        $this->display("promotion_chart");
    }


}